# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
from pandas import Series,DataFrame


# IO操作
def ioOperation():
    # 从粘贴板复制
    df = pd.read_clipboard()
    print(df)
    # 不输出index
    df.to_csv('df1.csv', index=False)
    print(df.to_json())


if __name__ == '__main__':
    data = {
        'Country': ['China', 'India', 'Brazil'],
        'Capital': ['Beijing', 'New Delhi', 'Brasilia'],
        'Population': ['1432732201', '1303171635', '207847528']
    }

    s1 = Series(data['Country'])
    s2 = Series(data['Capital'])
    s3 = Series(data['Population'])
    print(s1)

    df = DataFrame(data)
    print(df)

    # 迭代每一行
    for row in df.iterrows():
        print("index = {}, Series = {}".format(row[0], row[1]))

    # 通过Series创建DataFrame

    df_new = DataFrame([s1, s2, s3], index=['Country', 'Capital', 'Population'])
    print(df_new)
    df_new.rename(columns={0:'A', 1:'B', 3:'C'}, inplace=True)
    print(df_new)
    # 矩阵转置
    # print(df_new.T)
    # ioOperation()


